<?php
namespace Home\Model;
use Think\Model;

class OrdersureModel extends Model{
	 public function saveAll($data, $field = "") {
        if (empty($data) || !is_array($data)) {
            $this->error = L('_DATA_TYPE_INVALID_');
            return false;
        }
        $keys = array();
        $strdata = "";
        //数据处理
        foreach ($data as $k => $v) {
            if (is_array($v)) {
                $strdata.=$strdata ? ",('" . implode("','", $v) . "')" : "('" . implode("','", $v) . "')";
                $keys || $keys = array_keys($v);
            } else {
                $strdata = "('" . implode("','", $data) . "')";
                $keys = array_keys($data);
                break;
            }
        }
        $field || $field = $keys;
        if (is_string($field)) {
            $field = explode(",", $field);
        }
        $keys = "(`" . implode("`,`", $keys) . "`)";
        $sql = "INSERT INTO " . $this->trueTableName . $keys . "VALUES" . $strdata . " ON DUPLICATE KEY UPDATE ";
        $strkey = "";
        foreach ($field as $k => $v) {
            $strkey.=$strkey ? ",`" . $v . "`=VALUES(`" . $v . "`)" : "`" . $v . "`=VALUES(`" . $v . "`)";
        }
        $sql.=$strkey;
        $result = $this->execute($sql, true);
        return $result;
    }